package com.suibibk.springCloud.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.suibibk.springCloud.stock.mapper.StockMapper;
import com.suibibk.springCloud.stock.pojo.Stock;
import com.suibibk.springCloud.stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StockServiceImpl implements StockService {
    @Autowired
    StockMapper stockMapper;
    @Transactional
    @Override
    public void reduce(Long merchId) {
        System.out.println("扣减库存开始"+merchId);
        QueryWrapper<Stock> queryWrapper = new QueryWrapper<Stock>();
        queryWrapper.eq("merch_id",1l);
        Stock stock= stockMapper.selectOne(queryWrapper);
        UpdateWrapper<Stock> updateWrapper = new UpdateWrapper<Stock>();
        updateWrapper.eq("merch_id",1l);
        stock.setCount(stock.getCount()-1);
        stockMapper.update(stock,updateWrapper);
        System.out.println("扣减库存成功"+merchId);
    }
}
